package ma.myschool.app.webapp.action;

import java.io.Serializable;
import java.util.List;

import ma.myschool.app.dao.SearchException;
import ma.myschool.app.model.AnneeScolaire;
import ma.myschool.app.service.AnneeScolaireManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component("anneeScolaireList")
@Scope("session")
public class AnneeScolaireList extends BasePage implements Serializable {
    private String query;
    private AnneeScolaireManager anneeScolaireManager;

    @Autowired
    public void setAnneeScolaireManager(@Qualifier("anneeScolaireManager") AnneeScolaireManager anneeScolaireManager) {
        this.anneeScolaireManager = anneeScolaireManager;
    }

    public void setQuery(String query) {
        this.query = query;
    }

    public String getQuery() {
        return query;
    }

    public AnneeScolaireList() {
        setSortColumn("id"); // sets the default sort column
    }

    public List<AnneeScolaire> getAnneeScolaires() {
        try {
            return anneeScolaireManager.search(query, AnneeScolaire.class);
        } catch (SearchException se) {
            addError(se.getMessage());
            return sort(anneeScolaireManager.getAll());
        }
    }
    
    public int getAnneeScolairesSize(){
    	return getAnneeScolaires().size();
    }

    public String search() {
        return "success";
    }
}